//11. 盛最多水的容器
class Solution {
public:
    int maxArea(vector<int>& height) {
        int left = 0;
        int right = height.size() - 1;
        int ret = 0;
        while (left < right) {
            if (height[left] > height[right]) {
                ret = max(ret, (right - left) * height[right]);
                right--;
            } else {
                ret = max(ret, (right - left) * height[left]);
                left++;
            }
        }
        return ret;
    }
};

//42. 接雨水
class Solution {
public:
    int trap(vector<int>& height) {
        int left = 0;
        int right = height.size() - 1;
        int max_left = height[left];
        int max_right = height[right];
        int ret = 0;
        while (left < right) {
            if (height[left] > height[right]) {
                if (max_right > height[right])
                    ret += (max_right - height[right]);
                else
                    max_right = height[right];
                right--;
            } else {
                if (max_left > height[left])
                    ret += (max_left - height[left]);
                else
                    max_left = height[left];
                left++;
            }
        }
        return ret;
    }
};